
class Solution {
public:
    ListNode* swapPairs(ListNode* head) {
        ListNode *dummyHead = new ListNode(0,head),*temp = dummyHead;

        while (temp->next != nullptr && temp->next->next != nullptr) 
        {
            ListNode *node1 = temp->next,*node2 = temp->next->next;

            temp->next = node2,
            node1->next = node2->next,
            node2->next = node1,
            temp = node1;

        }
        ListNode* ans = dummyHead->next;
        delete dummyHead;
        return ans;
    }
};